<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>住院界面</title>
<script type="text/javascript" src="static/easyui/jquery.min.js"></script>
<script type="text/javascript" src="static/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="static/easyui/locale/easyui-lang-zh_CN.js"></script>
<link rel="stylesheet" href="static/easyui/themes/metro/easyui.css"/>
<link rel="stylesheet" href="static/easyui/themes/icon.css"/>
</head>
<body>
	<script type="text/javascript">
		$(function(){
			//搜索住院登记界面的通知单
			$("#inhospnotice_medicalcrad").searchbox({
				searcher:function(value,name){
					$.ajax({
		                url:"find-applyRegByid",
		                type:"post",
		                data:{'applyid':value},
		                dataType:"json",
		                success:function(data) {
		                    //医疗卡号
		                    $("#inlook-id-input").textbox('setValue',data.result[0]['cliniccard_id']);
		                    //病人姓名
		                    $("#insickname-input").textbox('setValue',data.result[0]['clinic_name']);
		                    //门诊科室
		                    $("#inuser-doctor-input").textbox('setValue',data.result[0]['section_name']);
		                    var sname = data.result[0]['section_name'];
		                    //科室下拉列表
		                    $('#sections2').combobox({
		                    	url:"init-zhsetion?sname="+sname,//数据源
		        	         	valueField: 'section_id',//实体类名字---主键id
		        		        textField: 'section_name',//需要显示在下拉框的实际内容
		        		        onLoadSuccess: function () {  //加载完成后,设置选中第一项
    			                    var val = $(this).combobox("getData");
    			                    for (var item in val[0]) {
    			                        if (item == "section_id") {
    			                        	//初始化数据默认选中第一个
    			                            $(this).combobox("select", val[0][item]);
    			                        }
    			                    }
    			               },
		        		        onSelect:function(row){
		        		        	//初始化医生
		        					$('#hospuserdoc2').combobox({
		        						 url: "init-hospuserdoctor?sid="+row["section_id"],
		        						 valueField: 'user_id',//实体类名字---主键id
		        					     textField: 'user_name',//需要显示在下拉框的实际内容	
		        					     onLoadSuccess: function () {  //加载完成后,设置选中第一项
		        			                    var val = $(this).combobox("getData");
		        			                    for (var item in val[0]) {
		        			                        if (item == "user_id") {
		        			                        	//初始化数据默认选中第一个
		        			                            $(this).combobox("select", val[0][item]);
		        			                        }
		        			                    }
		        			             }
		        					});
		        					
		        					//护士初始化数据
									$('#hospnurse2').combobox({   
							         	url:'init-hospusernurse?sid='+row["section_id"],//数据源
							         	valueField: 'user_id',//实体类名字---主键id
								        textField: 'user_name',//需要显示在下拉框的实际内容
								        editable:false,
							            panelHeight:'auto',//高度根据内容自动定
							            onLoadSuccess: function () {  //加载完成后,设置选中第一项
							                    var val = $(this).combobox("getData");
							                    for (var item in val[0]) {
							                        if (item == "user_id") {
							                        	//初始化数据默认选中第一个
							                            $(this).combobox("select", val[0][item]);
							                        }
							                    }
							             }
						 
							        });
			
		        					
		        					//病房初始化
		        					$('#room2').combobox({
		            					 url: "init-sickroombed?sid="+row["section_id"],
		            					 valueField: 'sickroom_id',//实体类名字---主键id
		            				     textField: 'sickroom_name',//需要显示在下拉框的实际内容
		            				     onLoadSuccess: function () {  //加载完成后,设置选中第一项
		        			                    var val = $(this).combobox("getData");
		        			                    for (var item in val[0]) {
		        			                        if (item == "sickroom_id") {
		        			                        	//初始化数据默认选中第一个
		        			                            $(this).combobox("select", val[0][item]);
		        			                        }
		        			                    }
		        			                    //床位号的下拉列表
		            						     $("#bed2").combobox("setValue",'');
		            						     var roomid = $('#room2').combobox('getValue'); 
		            							 $.ajax({
		            							 type: "Post",
		            							 url: "select-roombedno?roomid="+roomid,
		            							 cache: false,
		            							 dataType : "json",
		            							 success: function(data){
		            								 $("#bed2").combobox("loadData",data);
		            								 }
		            							 }); 
		        			             }
		 
		        					})	
		        		        }	        	
		                    });
		                 }
		            });
					
				}
			});

			
			//床位初始化
			$('#bed2').combobox({   
	         	//url:'init-bedno',//数据源
	         	valueField: 'bed_id',//实体类名字---主键id
		        textField: 'bed_no',//需要显示在下拉框的实际内容
		        editable:false,
	            panelHeight:'auto',//高度根据内容自动定
	            onLoadSuccess: function () {  //加载完成后,设置选中第一项
	                    var val = $(this).combobox("getData");
	                    for (var item in val[0]) {
	                        if (item == "bed_id") {
	                        	//初始化数据默认选中第一个
	                            $(this).combobox("select", val[0][item]);
	                        }
	                    }
	             }
 
	        });
			
			
			
			//住院登记的信息
			$('#logininform-dg').datagrid({
			    url:'reg-hosprecord',
			    method:"Post",
			    pagination:true,
			    pageNumber:1,
			    pageSize:10,
			    pageList:[10,15],
			    columns:[[
			    	{field:'hosp_id',title:'住院号',width:90},
					{field:'clinic_name',title:'病人姓名',width:80},
					{field:'clinic_sex',title:'性别',width:70},
					{field:'clinic_age',title:'年龄',width:70},
					{field:'section_name',title:'科室',width:70},
					{field:'user_name',title:'主治医生',width:100},
					{field:'nursename',title:'护士姓名',width:100},
					{field:'sickroom_name',title:'病房号',width:83},
					{field:'bed_no',title:'床位号',width:80},
					{field:'cash_dmoney',title:'押金余额',width:70},
					{field:'hosp_time',formatter:comFormatDate,title:'登记时间',width:160},
					{field:'hosp_people',title:'登记员',width:72}
			    ]]
			});

			//从门诊过来的新增住院登记和医疗卡的确定按钮
			$("#advice-confirm").click(function(){
				$('#inform-for').form({
				    url:'add-inform',
				    onSubmit: function(){
				    	
				    },
				    success:function(data){
				    	var hospid = $("#loginhospid").textbox('getValue');
				    	$.messager.show({
	                        title:'提示信息' , 
	                        msg:'住院登记新增成功!【'+hospid+'】请查看登记记录'
	                    });
				    	//$('#inform-for').form("clear");//清空文本
				    	$('#logininform-dg').datagrid('reload');
				    }
				}).submit();
			});
			
			//取消按钮
			$("#close-inform").click(function(){
				//清除文本框
		    	$('#inform-for').form("clear");
			});


			
		});
		
		
		//根据姓名，住院号查询住院登记记录
		function qq(value,name){
			var hid="";
			var cname="";
			if(name=="姓名查询"){
				cname=value;
			}else if(name=="住院号查询"){
				hid = value;
			}
		    $('#logininform-dg').datagrid({
			    url:'reg-hosprecord',
			    queryParams:{
			    	clinicname:cname,
			    	hospid:hid
			    },
			    method:"Post",
			    pagination:true,
			    pageNumber:1,
			    pageSize:10,
			    pageList:[10,15],
			    columns:[[
			    	{field:'hosp_id',title:'住院号',width:90},
					{field:'clinic_name',title:'病人姓名',width:80},
					{field:'clinic_sex',title:'性别',width:70},
					{field:'clinic_age',title:'年龄',width:70},
					{field:'section_name',title:'科室',width:70},
					{field:'user_name',title:'主治医生',width:100},
					{field:'nursename',title:'护士姓名',width:100},
					{field:'sickroom_name',title:'病房号',width:83},
					{field:'bed_no',title:'床位号',width:80},
					{field:'cash_dmoney',title:'押金余额',width:70},
					{field:'hosp_time',formatter:comFormatDate,title:'登记时间',width:160},
					{field:'hosp_people',title:'登记员',width:72}
			    ]]
			});  
       }
		
		/**
		 * 时间格式YYY-mm-dd hh:mm:ss
		 */
		function comFormatDate(date) {
			var day = new Date(date); 
			var Year = 0; 
			var Month = 0; 
			var Day = 0; 
			var CurrentDate = ""; 
			//初始化时间 
			Year= day.getFullYear();
			Month= day.getMonth()+1; 
			Day = day.getDate(); 
			Hour = day.getHours(); 
			 Minute = day.getMinutes(); 
			 Second = day.getSeconds(); 
			CurrentDate += Year + "-"; 
			if (Month >= 10 ) { 
				CurrentDate += Month + "-"; 
			}else { 
				CurrentDate += "0" + Month + "-"; 
			} 
			if (Day >= 10 ) { 
				CurrentDate += Day ; 
			}else { 
				CurrentDate += "0" + Day ; 
			} 
			if(Hour>=10){
				CurrentDate +=" "+Hour;
			}else{
				CurrentDate +=" "+"0"+Hour;
			}
			if(Minute>=10){
				CurrentDate +=":"+Minute;
			}else{
				CurrentDate +=":"+"0"+Minute;
			}
			if(Second>=10){
				CurrentDate +=":"+Second;
			}else{
				CurrentDate +=":"+"0"+Second;
			}
			return CurrentDate; 
		}
	</script>
	<!--  入院基本资料 -->
	<fieldset style="border:1px solid #A6A6A6;border-radius:6px;width:1050px;margin: 15px auto;">
		<legend style="font-size:15px;">登记信息</legend>
		<form id="inform-for" method="post">
			<div class="loginform">
				<p style="margin-top: 10px;">
					<a>
					<input id="inhospnotice_medicalcrad" class="easyui-searchbox" data-options="label:'住院通知号',height:30" style="width:200px"></input>
					</a>
					<a><input id="inlook-id-input" class="easyui-textbox" name="cliniccardId" data-options="label:'医疗卡号',height:30,required:true" style="width:200px"></a>
		    		<a><input id="insickname-input" name="clinicName" class="easyui-textbox" data-options="label:'病人姓名',height:30,required:true" style="width:200px"></a>
					<a><input id="inuser-doctor-input" class="easyui-textbox" name="userdoctorname" data-options="label:'门诊科室',height:30" style="width:230px"></a>
				</p>
				<p style="margin-top: 20px;">	
					<a>
					<input id="loginhospid" name="hospId" class="easyui-textbox" data-options="label:'住院号',height:30" value="${hospid }" style="width:200px">
					</a>
					<a>
						<select id="sections2" class="easyui-combobox" data-options="label:'科室',height:30" name="sectionname" style="width:200px">
						</select>				
					</a>	
					<a>
						<select id="hospuserdoc2" class="easyui-combobox" data-options="label:'住院医生',height:30" name="hospdoctorname" style="width:200px">
						</select>				
					</a>
					<a>
						<select id="hospnurse2" class="easyui-combobox" data-options="label:'护士姓名',height:30" name="hospnursename" style="width:230px">
						</select>				
					</a>
					
				</p>
				<p style="margin-top: 20px;">	
				    <a>
					   <select id="room2" class="easyui-combobox" data-options="label:'病房名称',height:30" name="sickroomId" style="width:200px">
					   </select>					
					</a>
				    <a>
					   <select id="bed2" class="easyui-combobox" data-options="label:'床位号',height:30" name="bedId" style="width:200px">
						</select>					
					</a>			
					<a>
						<input type="text" class="easyui-numberbox" name="cashMoney" value="500" data-options="label:'押金余额',height:30,required:true" style="width:200px;">
					</a>
					<a>
					<input class="easyui-textbox" name="hospPeople" data-options="label:'登记员',height:30,required:true" value="${user.userName}" style="width:230px">
					</a>
				</p>
				
				<p style="margin-top: 30px;">
			    	<a id="advice-confirm" style="margin-left:40px;width:100px;height:30px;border-radius:6px;" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
				    <a id="close-inform"style="margin-left:100px;width:100px;height:30px;border-radius:6px;" class="easyui-linkbutton" iconCls="icon-cancel">清空</a>				    
				</p>
				
			</div>
		</form>   
		
	</fieldset>

	<!-- 病人信息记录的面板 <span style="margin-left: 9px;">输入姓名：</span>
		<input id="sickuser_input" class="easyui-textbox" data-options="" style="width:190px;">-->
	<fieldset class="login-record" style="border:1px solid #A6A6A6;border-radius:6px;width:1050px;height:350px;margin: 15px auto;">
		<legend style="font-size:15px;">登记记录</legend>
		<!-- 搜索框 -->
		<input id="ss" class="easyui-searchbox" style="width:300px"
		    data-options="searcher:qq,prompt:'Please Input Value',menu:'#mm'"></input>
		<div id="mm" style="width:120px">
		    <div data-options="iconCls:'icon-ok'">姓名查询</div>
		    <div>住院号查询</div>
		</div>
		<table id="logininform-dg" class="logininform-table easyui-datagrid" style="height:300px;"
		data-options="toolbar:'#logininform-tb',fitColumns:false,singleSelect:true">
		</table>

	</fieldset>
	<!-- 弹框提示 -->
    <div id="warminginhosp-win" class="easyui-window"  title="提示框" style="width:300px;height:156px"
    data-options="iconCls:'icon-save',modal:true,resizable:false,collapsible:false,maximizable:false,minimizable:false,closed:true">
          <p class="window-in" style=" margin-left: 72px;font-size: 16px;margin-top: 47px;">
          </p>
    </div>
</body>
</html>